<%@ Page Language="C#" Theme="Defaultsys" AutoEventWireup="true" CodeFile="ContactPageField.aspx.cs"
    Inherits="ContactPageField" Title="Rapport Plan System - Contact page field"
    MasterPageFile="~/MasterPage.master" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content runat="server" ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1">

    <script type="text/javascript" language="javascript">
        // Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

        function whichBrs() {
            var agt=navigator.userAgent.toLowerCase();
            if (agt.indexOf("opera") != -1) return 'Opera';
            if (agt.indexOf("staroffice") != -1) return 'Star Office';
            if (agt.indexOf("webtv") != -1) return 'WebTV';
            if (agt.indexOf("beonex") != -1) return 'Beonex';
            if (agt.indexOf("chimera") != -1) return 'Chimera';
            if (agt.indexOf("netpositive") != -1) return 'NetPositive';
            if (agt.indexOf("phoenix") != -1) return 'Phoenix';
            if (agt.indexOf("firefox") != -1) return 'Firefox';
            if (agt.indexOf("safari") != -1) return 'Safari';
            if (agt.indexOf("skipstone") != -1) return 'SkipStone';
            if (agt.indexOf("msie") != -1) return 'Internet Explorer';
            if (agt.indexOf("netscape") != -1) return 'Netscape';
            if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
            if (agt.indexOf('\/') != -1) {
            if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0,agt.indexOf('\/'));}
            else return 'Netscape';} else if (agt.indexOf(' ') != -1)
            return navigator.userAgent.substr(0,agt.indexOf(' '));
            else return navigator.userAgent;
        }
        

        function FieldTypeChange(obj)
        {
        
            var divComboboxValues = document.getElementById("ctl00_ContentPlaceHolder1_comboValue");            
            var divRowsValues = document.getElementById("ctl00_ContentPlaceHolder1_rowsId");            
            var divColsValues = document.getElementById("ctl00_ContentPlaceHolder1_colsId");            
            var cmb = document.getElementById("ctl00_ContentPlaceHolder1_cmbFieldType");
            
            if (whichBrs()=='Internet Explorer')
            {
                switch (cmb[cmb.selectedIndex].value)
                {
                     case "1":
                        divComboboxValues.style.display = "inline";
                        divRowsValues.style.display = "none";
                        divColsValues.style.display = "none";
                        break;
                    case "4":
                        divComboboxValues.style.display = "none";
                        divRowsValues.style.display = "inline";
                        divColsValues.style.display = "inline";
                        break;
                    default:
                        divComboboxValues.style.display = "none";
                        divRowsValues.style.display = "none";
                        divColsValues.style.display = "none";
                        break;
                }
            }
             
            if (whichBrs()=='Firefox')
            {
                switch (cmb[cmb.selectedIndex].value)
                {

                    case "1":
                        divComboboxValues.style.visibility = "visible";
                        divRowsValues.style.visibility = "collapse";
                        divColsValues.style.visibility = "collapse";
                        break;
                    case "4":
                        divComboboxValues.style.visibility = "collapse";
                        divRowsValues.style.visibility = "visible";
                        divColsValues.style.visibility = "visible";
                        break;
                    default:
                        divComboboxValues.style.visibility = "collapse";
                        divRowsValues.style.visibility = "collapse";
                        divColsValues.style.visibility = "collapse";
                        break;
                }
            }
        }
        
        function AddValue()
        {
            
            var newValue = document.getElementById("ctl00_ContentPlaceHolder1_txtComboboxValue").value;
            var o = document.createElement("option");
            o.text = newValue;
            o.value = newValue;
            document.getElementById("ctl00$ContentPlaceHolder1$lstComboboxValues").add(o);
            document.getElementById("ctl00$ContentPlaceHolder1$hiddenComboBoxValues").value += newValue+";";
            document.getElementById("ctl00_ContentPlaceHolder1_txtComboboxValue").value = "";
            document.getElementById("ctl00_ContentPlaceHolder1_txtComboboxValue").focus();
            return false;
        }       
        
        function RemoveValue()
        {        
            var lst = document.getElementById("ctl00_ContentPlaceHolder1_lstComboboxValues");
            if (lst.selectedIndex != -1)
            {
                lst.remove(lst.selectedIndex);
            }
            
            document.getElementById("ctl00$ContentPlaceHolder1$hiddenComboBoxValues").value = "";
            for (i=0; i<lst.options.length; i++)
            {
                document.getElementById("ctl00$ContentPlaceHolder1$hiddenComboBoxValues").value += lst.options[i].value+";";
            }
            
            return false;
        }   
        
	
        
        function validateRange()
        {
          var s = document.frmInput.txtInput.value;
          var A = document.frmInput.txtA.value;
          var B = document.frmInput.txtB.value;

          switch (isIntegerInRange(s, A, B))
          {
             case true:
                alert(s + " is in range from " + A + " to " + B)
                break;
             case false:
                alert(s + " is not in range from " + A + " to " + B)
          }
        }

        // isIntegerInRange (STRING s, INTEGER a, INTEGER b)
        function isIntegerInRange (s, a, b)
        {   if (isEmpty(s))
             if (isIntegerInRange.arguments.length == 1) return false;
             else return (isIntegerInRange.arguments[1] == true);

          // Catch non-integer strings to avoid creating a NaN below,
          // which isn't available on JavaScript 1.0 for Windows.
          if (!isInteger(s, false)) return false;

          // Now, explicitly change the type to integer via parseInt
          // so that the comparison code below will work both on
          // JavaScript 1.2 (which typechecks in equality comparisons)
          // and JavaScript 1.1 and before (which doesn't).
          var num = parseInt (s);
          return ((num >= a) && (num <= b));
        }

        function isInteger (s)
        {
          var i;

          if (isEmpty(s))
          if (isInteger.arguments.length == 1) return 0;
          else return (isInteger.arguments[1] == true);

          for (i = 0; i < s.length; i++)
          {
             var c = s.charAt(i);

             if (!isDigit(c)) return false;
          }

          return true;
        }

        function isEmpty(s)
        {
          return ((s == null) || (s.length == 0))
        }

        function isDigit (c)
        {
          return ((c >= "0") && (c <= "9"))
        }
        
        function ValidateRows(oSrc, args)
		{

		    var objCombo = document.getElementById('ctl00_ContentPlaceHolder1_cmbFieldType');
            var objRows = document.getElementById("ctl00_ContentPlaceHolder1_txtRows");            
	    

		    args.IsValid = true;           
		    if (objRows == null)
		    {
		        return true;
		    }
            
            if ((objCombo.value == "4") && (objRows.value!="" && !isInteger (objRows.value)))
                args.IsValid = false;               
        }	

     
        function ValidateColumns(oSrc, args)
		{
		    var objCombo = document.getElementById('ctl00_ContentPlaceHolder1_cmbFieldType');
            var objCols = document.getElementById("ctl00_ContentPlaceHolder1_txtColumns");            
	    

		    args.IsValid = true;           
		    if (objCols == null)
		    {
		        return true;
		    }
            
            if ((objCombo.value == "4") && (objCols.value!="" && !isInteger (objCols.value)))
                args.IsValid = false;               
        }	
        
    </script>

    <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td class="contTable">
                <table >
                    <tr>
                        <td>
                            Name:</td>
                        <td style="width: 289px">
                            <asp:TextBox ID="txtName" runat="server" Width="279px"></asp:TextBox></td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName"
                                CssClass="error" ErrorMessage="Name is required" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Type:</td>
                        <td>
                            <asp:DropDownList ID="cmbFieldType" runat="server" Width="284px">
                                <asp:ListItem Value="0">textbox</asp:ListItem>
                                <asp:ListItem Value="2">checkbox</asp:ListItem>
                                <asp:ListItem Value="1">combobox</asp:ListItem>
                                <asp:ListItem Value="3">datetime picker</asp:ListItem>
                                <asp:ListItem Value="4">textarea</asp:ListItem>
                            </asp:DropDownList></td>
                            <td></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Available to:</td>
                        <td>
                            <asp:ListBox ID="lstContactTypes" runat="server" Width="284px" Rows="15" SelectionMode="Multiple">
                            </asp:ListBox></td>
                            <td></td>
                    </tr>
                    <tr id="comboValue" runat="server">
                        <td valign="top">
                            Comobobox values:</td>
                        <td>
                            <asp:TextBox ID="txtComboboxValue" runat="server" Width="222px"></asp:TextBox>
                            <asp:Button ID="btnAddValue" runat="server" Text="Add" Width="56px" /><br />
                            <asp:ListBox ID="lstComboboxValues" runat="server" Width="286px" Rows="10"></asp:ListBox>
                            <br />
                            <asp:Button ID="btnDelete" runat="server" Text="Remove" /><asp:HiddenField ID="hiddenComboBoxValues"
                                runat="server" />
                        </td>
                        <td></td>
                    </tr>
                    <tr id="rowsId" runat="server" >
                        <td valign="top">
                            Rows:</td>
                        <td>
                            <asp:TextBox ID="txtRows" runat="server" Width="50px">20</asp:TextBox>
                            <asp:CustomValidator ID="cvRows" runat="server" ErrorMessage="(*)Integer value is required "
                                ClientValidationFunction="ValidateRows" Display="Dynamic">*</asp:CustomValidator></td>
                                <td></td>
                    </tr>
                    <tr id="colsId" runat="server" >
                        <td valign="top" >
                            Columns:</td>
                        <td>
                            <asp:TextBox ID="txtColumns" runat="server" Width="50px">25</asp:TextBox>
                            <asp:CustomValidator ID="cvColumns" runat="server" ControlToValidate="txtColumns"
                                ErrorMessage="(*)Integer value is reuqired" ClientValidationFunction="ValidateColumns" Display="Dynamic">*</asp:CustomValidator></td>
                                <td></td>
                    </tr>
                    <tr  id="trSave" style="position:relative;">
                        <td colspan="3">
                            <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="Save" />
                            <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="Cancel" CausesValidation="false" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtName"
                                CssClass="error" ErrorMessage="(*)Name is required" SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:CustomValidator ID="cvRows1" runat="server" ControlToValidate="txtRows" ErrorMessage="(*)Integer value is required "
                                ClientValidationFunction="ValidateRows" Display="Dynamic">(*)Integer value is required </asp:CustomValidator></td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:CustomValidator ID="cvColumns2" runat="server" ControlToValidate="txtColumns"
                                ErrorMessage="(*)Integer value is required" ClientValidationFunction="ValidateColumns" Display="Dynamic">(*)Integer value is required</asp:CustomValidator></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <script type="text/javascript" language="javascript">
 
    
        if (whichBrs()=='Firefox')
        {
            document.getElementById("ctl00_ContentPlaceHolder1_comboValue").style.visibility = "collapse";
            document.getElementById("ctl00_ContentPlaceHolder1_rowsId").style.visibility = "collapse";
            document.getElementById("ctl00_ContentPlaceHolder1_colsId").style.visibility = "collapse";
            
            var cmb = document.getElementById("ctl00_ContentPlaceHolder1_cmbFieldType");
            switch (cmb[cmb.selectedIndex].value)
            {
                 case "1":
                    document.getElementById("ctl00_ContentPlaceHolder1_comboValue").style.visibility = "visible";
                    break;
                 case "4":
                    document.getElementById("ctl00_ContentPlaceHolder1_rowsId").style.visibility = "visible";
                    document.getElementById("ctl00_ContentPlaceHolder1_colsId").style.visibility = "visible";
                    break;
                  default:
                    break;
            }
        }
        
        if (whichBrs()=='Internet Explorer')
        {
            document.getElementById("ctl00_ContentPlaceHolder1_comboValue").style.display = "none";
            document.getElementById("ctl00_ContentPlaceHolder1_rowsId").style.display = "none";
            document.getElementById("ctl00_ContentPlaceHolder1_colsId").style.display = "none";
            
            var cmb = document.getElementById("ctl00_ContentPlaceHolder1_cmbFieldType");
            switch (cmb[cmb.selectedIndex].value)
            {
                 case "1":
                    document.getElementById("ctl00_ContentPlaceHolder1_comboValue").style.display = "inline";
                    break;
                 case "4":
                    document.getElementById("ctl00_ContentPlaceHolder1_rowsId").style.display = "inline";
                    document.getElementById("ctl00_ContentPlaceHolder1_colsId").style.display = "inline";
                    break;
                  default:
                    break;
            }
        }

    </script>
</asp:Content>
